#include "PlatformProperty.h"

// HY11 [SW_FC_004_043]第一排座椅滑移1stRowSeatLengthAdjustment 第一排乘客座椅前后滑移百分比
SYSTEM_READ_PROPERTY(SEAT_FORE_AFT_POS, int32_t) {
    builder.area(VehicleAreaSeat::ROW_1_LEFT)
        .initValue([]() { return 0; })
        .withStatusBySignals(
            []([[maybe_unused]] const PropertyStatus& last) {
                VHALOG.d(
                    "SEAT_FORE_AFT_POS drvr cc472[%d], cc1173[%d], cc184[%d]",
                    SIGNAL.getcarconfig472(), SIGNAL.getcarconfig1173(), SIGNAL.getcarconfig184());

                if (SIGNAL.carConfigIs(SignalRX::carconfig472,
                                       sdb::CarConfig472::_02,
                                       sdb::CarConfig472::_03) &&
                    SIGNAL.carConfigIs(SignalRX::carconfig1173,
                                       sdb::CarConfig1173::_02) &&
                    SIGNAL.carConfigIs(SignalRX::carconfig184,
                                       sdb::CarConfig184::_02,
                                       sdb::CarConfig184::_03,
                                       sdb::CarConfig184::_04)) {
                    VHALOG.d("SEAT_FORE_AFT_POS drvr Active");
                    return PropertyStatus::Active;
                } else {
                    VHALOG.d("SEAT_FORE_AFT_POS drvr NotAvailable");
                    return PropertyStatus::NotAvailable;
                }
            },
            SignalRX::carconfig1173,
            SignalRX::carconfig472,
            SignalRX::carconfig184)
        .withValueBySignals(
            []([[maybe_unused]] const int32_t& last) {
                auto qf = SIGNAL.getDrvrSeatPosPercSeatPosSldQF();
                auto movePercent = static_cast<int32_t>(SIGNAL.getDrvrSeatPosPercSeatPosSldPerc());
                VHALOG.d("SEAT_FORE_AFT_POS drvr DrvrSeatPosPercSeatPosSldQF [%d],DrvrSeatPosPercSeatPosSldPerc[%d]", qf, movePercent);

                if (movePercent >= 0 && movePercent <= 100 &&
                    qf == sdb::Qf1::DataCalcdWithDevDefd) {
                    return movePercent;
                }
                return last;
            },
            SignalRX::DrvrSeatPosPercSeatPosSldQF,
            SignalRX::DrvrSeatPosPercSeatPosSldPerc)
        .area(VehicleAreaSeat::ROW_1_RIGHT)
        .initValue([]() { return 0; })
        .withStatusBySignals(
            []([[maybe_unused]] const PropertyStatus& last) {
                VHALOG.d(
                    "SEAT_FORE_AFT_POS pass  "
                    "cc472[%d], cc1174[%d], cc184[%d]",
                    SIGNAL.getcarconfig472(), SIGNAL.getcarconfig1174(), SIGNAL.getcarconfig184());

                if (SIGNAL.carConfigIs(SignalRX::carconfig472,
                                       sdb::CarConfig472::_02) &&
                    SIGNAL.carConfigIs(SignalRX::carconfig1174,
                                       sdb::CarConfig1174::_02) &&
                    SIGNAL.carConfigIs(SignalRX::carconfig184,
                                       sdb::CarConfig184::_04)) {
                    VHALOG.d("SEAT_FORE_AFT_POS pass Active");
                    return PropertyStatus::Active;
                } else {
                    VHALOG.d("SEAT_FORE_AFT_POS pass NotAvailable");
                    return PropertyStatus::NotAvailable;
                }
            },
            SignalRX::carconfig1174, SignalRX::carconfig472, SignalRX::carconfig184)
        .withValueBySignals(
            []([[maybe_unused]] const int32_t& last) {
                auto qf = SIGNAL.getPassSeatPosPercSeatPosSldQF();
                auto movePercent = static_cast<int32_t>(SIGNAL.getPassSeatPosPercSeatPosSldPerc());
                VHALOG.d("SEAT_FORE_AFT_POS pass PassSeatPosPercSeatPosSldQF [%d],PassSeatPosPercSeatPosSldPerc[%d]", qf, movePercent);
                if (movePercent >= 0 && movePercent <= 100 &&
                    qf == sdb::Qf1::DataCalcdWithDevDefd) {
                    return movePercent;
                }
                return last;
            },
            SignalRX::PassSeatPosPercSeatPosSldQF,
            SignalRX::PassSeatPosPercSeatPosSldPerc)
        // HY11 [SW_FC_004_049]第二排座椅滑移-二排左侧座椅实时位置
        .area(VehicleAreaSeat::ROW_2_LEFT)
        .initValue([]() { return 0; })
        .withStatusBySignals(
            []([[maybe_unused]] const PropertyStatus& last) {
                VHALOG.d(
                    "SEAT_FORE_AFT_POS ROW_2_LEFT cc474[%d], cc551[%d]",
                    SIGNAL.getcarconfig474(),  SIGNAL.getcarconfig551());

                if (SIGNAL.carConfigIs(SignalRX::carconfig474,
                                       sdb::CarConfig474::_02,
                                       sdb::CarConfig474::_04,
                                       sdb::CarConfig474::_05,
                                       sdb::CarConfig474::_81) &&
                    SIGNAL.carConfigIs(SignalRX::carconfig551,
                                       sdb::CarConfig551::_02)) {
                    VHALOG.d("SEAT_FORE_AFT_POS ROW_2_LEFT Active");
                    return PropertyStatus::Active;
                } else {
                    VHALOG.d("SEAT_FORE_AFT_POS ROW_2_LEFT NotAvailable");
                    return PropertyStatus::NotAvailable;
                }
            },
            SignalRX::carconfig474,
            SignalRX::carconfig551)
        .withValueBySignals(
            []([[maybe_unused]] const int32_t& last) {
                //信号质量
                auto qf = SIGNAL.getRowSecLeSldPosPercSeatPosQf();
                auto movePercent = static_cast<int32_t>(SIGNAL.getRowSecLeSldPosPercSeatPosPerc());
                VHALOG.d("SEAT_FORE_AFT_POS ROW_2_LEFT RowSecLeSldPosPercSeatPosQf [%d],RowSecLeSldPosPercSeatPosPerc[%d]", qf, movePercent);

                if (movePercent >= 0 && movePercent <= 100 &&
                    qf == sdb::Qf1::DataCalcdWithDevDefd) {
                    return movePercent;
                }
                return last;
            },
            SignalRX::RowSecLeSldPosPercSeatPosQf,
            SignalRX::RowSecLeSldPosPercSeatPosPerc)
        // 二排右侧座椅实时位置
        .area(VehicleAreaSeat::ROW_2_RIGHT)
        .initValue([]() { return 0; })
        .withStatusBySignals(
            []([[maybe_unused]] const PropertyStatus& last) {
                VHALOG.d(
                    "SEAT_FORE_AFT_POS ROW_2_RIGHT cc474[%d], cc551[%d]",
                    SIGNAL.getcarconfig474(),  SIGNAL.getcarconfig551());

                if (SIGNAL.carConfigIs(SignalRX::carconfig474,
                                       sdb::CarConfig474::_02,
                                       sdb::CarConfig474::_04,
                                       sdb::CarConfig474::_05,
                                       sdb::CarConfig474::_81) &&
                    SIGNAL.carConfigIs(SignalRX::carconfig551,
                                       sdb::CarConfig551::_02)) {
                    VHALOG.d("SEAT_FORE_AFT_POS ROW_2_RIGHT Active");
                    return PropertyStatus::Active;
                } else {
                    VHALOG.d("SEAT_FORE_AFT_POS ROW_2_RIGHT NotAvailable");
                    return PropertyStatus::NotAvailable;
                }
            },
            SignalRX::carconfig474,
            SignalRX::carconfig551)
        .withValueBySignals(
            []([[maybe_unused]] const int32_t& last) {
                //信号质量
                auto qf = SIGNAL.getRowSecRiSldPosPercSeatPosQf();
                auto movePercent = static_cast<int32_t>(SIGNAL.getRowSecRiSldPosPercSeatPosPerc());
                VHALOG.d("SEAT_FORE_AFT_POS ROW_2_RIGHT RowSecRiSldPosPercSeatPosQf [%d],RowSecRiSldPosPercSeatPosPerc[%d]", qf, movePercent);

                if (movePercent >= 0 && movePercent <= 100 &&
                    qf == sdb::Qf1::DataCalcdWithDevDefd) {
                    return movePercent;
                }
                return last;
            },
            SignalRX::RowSecRiSldPosPercSeatPosQf,
            SignalRX::RowSecRiSldPosPercSeatPosPerc);
};
